import 'dart:async';
import 'dart:typed_data';

import 'package:flutter/services.dart';

typedef AudioFrameCallback = void Function(Uint8List data);


class AgoraRtcRawdata {
  static const MethodChannel _channel =
      const MethodChannel('agora_rtc_rawdata');
  static AudioFrameCallback _onRecordFrameCallback;

  static void init(){
    _channel.setMethodCallHandler((methodCall) async {
      switch (methodCall.method) {
        case 'onRecordFrame':

        //print("onRecordFrame:"+data.length.toString());
          if(_onRecordFrameCallback != null){
            Uint8List data = methodCall.arguments;
            _onRecordFrameCallback(data);
          }
          break;
        default:
          throw MissingPluginException();
      }
    });
  }

  static Future<void> registerAudioFrameObserver(int engineHandle,AudioFrameCallback callback) {
    _onRecordFrameCallback = callback;
    return _channel.invokeMethod('registerAudioFrameObserver', engineHandle);
  }

  static Future<void> unregisterAudioFrameObserver() {
    _onRecordFrameCallback = null;
    return _channel.invokeMethod('registerAudioFrameObserver');
  }

  static Future<void> registerVideoFrameObserver(int engineHandle) {
    return _channel.invokeMethod('registerVideoFrameObserver', engineHandle);
  }

  static Future<void> unregisterVideoFrameObserver() {
    return _channel.invokeMethod('unregisterVideoFrameObserver');
  }
}
